/*
 * InvoiceButton.java
 * 
 * @version 1.0, April 29, 2011
 * CS 2340 Team 10: Cyberdyne Systems
 */
package edu.gatech.oad.cyberdoc.view.invoice;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.BorderFactory;
import javax.swing.JButton;

import edu.gatech.oad.cyberdoc.presenter.Presenter;

/**
 * Represents an invoice in a list in the GUI.  This class stores the ID of the
 * invoice and fires events to the Presenter when it is clicked.
 * 
 * @author John Girata
 * @version 1.0, April 29, 2011
 */
public class InvoiceButton extends JButton implements ActionListener {
	
	/**
	 * The ID of the invoice represented by this button.
	 */
	private final int id;
	
	/**
	 * Creates a new invoice entry with the parameters given.
	 * 
	 * @param id The ID of the invoice
	 * @param patient The patient associated with this invoice
	 * @param date The date associated with this invoice
	 */
	public InvoiceButton(int id, String patient, Date date) {
		super(patient + " on " + date.toString());
		
		addActionListener(this);
		setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		
		this.id = id;
	}

	/**
	 * Responds to this button being clicked.
	 * 
	 * @param e The ActionEvent fired
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		Presenter.getInstance().viewInvoice(id);
	}
}
